package com.acme.domain.bank;

import com.acme.domain.account.Account;
import com.acme.domain.account.CheckingAccount;
import com.acme.domain.client.Client;

import java.util.*;

//Weird task. Wonder if they heard about personal data privacy
public class BankReport {

    public static int getNbOfCustomers(Bank bank) {
        return bank.getClients().size();
    }

    public static int getNbOfAccounts(Bank bank) {
        int numberOfAccount = 0;
        final Set<Client> clients = bank.getClients();
        for (Client client : clients) {
            numberOfAccount += client.getAccounts().size();
        }
        return numberOfAccount;
    }

    public static double getBankCredit(Bank bank) {
        int credit = 0;
        final Set<Client> clients = bank.getClients();
        for (Client client: clients) {
            Set<Account> accounts = client.getAccounts();
            for (Account account : accounts) {
                if (account instanceof CheckingAccount) {
                    credit += ((CheckingAccount) account).getCredit();
                }
            }
        }
        return credit;
    }

    public static Map<Client, Set<Account> > getCustomerAccount(Bank bank) {
        Map<Client, Set<Account> > map = new HashMap<>();
        Set<Client> clients = bank.getClients();
        for (Client client: clients) {
            map.put(client, client.getAccounts());
        }
        return map;
    }
}
